# 啥都别说了,判断就完事了;结果最后死在了0上,单独一个0还是要输出Zero的
class Solution:
    num_dict = {0: "", 1: " One", 2: " Two", 3: " Three", 4: " Four", 5: " Five", 6: " Six", 7: " Seven", 8: " Eight",
                9: " Nine", 10: " Ten", 11: " Eleven", 12: " Twelve", 13: " Thirteen", 14: " Fourteen", 15: " Fifteen",
                16: " Sixteen", 17: " Seventeen", 18: " Eighteen", 19: " Nineteen"}
    num_90_dict = {2: " Twenty", 3: " Thirty", 4: " Forty", 5: " Fifty", 6: " Sixty", 7: " Seventy",
                   8: " Eighty", 9: " Ninety"}
    houzhui_dict = {0: "", 1: " Thousand", 2: " Million", 3: " Billion"}

    def numberToWords(self, num: int) -> str:
        if num == 0:
            return "Zero"
        res, index = "", 0
        while num:
            mid_num = num % 1000
            if mid_num:
                mid_res = ""
                if mid_num // 100:
                    mid_res += Solution.num_dict[mid_num // 100] + " Hundred"
                mid_num %= 100
                if mid_num < 20:
                    mid_res += Solution.num_dict[mid_num]
                else:
                    mid_res += Solution.num_90_dict[mid_num // 10]
                    mid_res += Solution.num_dict[mid_num % 10]
                res = mid_res + Solution.houzhui_dict[index] + res
            num //= 1000
            index += 1
        return res.lstrip()


a = Solution()
print(a.numberToWords(1000))
print(a.numberToWords(50))
print(a.numberToWords(12345))
print(a.numberToWords(1234567))
print(a.numberToWords(123456789))
print(a.numberToWords(100))
print(a.numberToWords(1100))
print(a.numberToWords(1000000))
